package com.zjsm.system;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;

import javax.swing.*;

import com.zjsm.component.CircleButton;
import com.zjsm.component.ImagePanel;
import com.zjsm.gobang.GoBang_PP;
import com.zjsm.gobang.IChess;
import com.zjsm.music.Mention;

public class ChangeModel extends JFrame implements IChess{
	/**
	 * 
	 */
	private static final long serialVersionUID = -4803218142185599561L;
	private CircleButton mc, mm;
	private JLabel top = new JLabel("这就是命五子棋");
	protected final ImagePanel goBang = new ImagePanel("resource/img/gobang.jpg");
	
	public ChangeModel() {
		this.setTitle("这就是命五子棋");
		this.setLocationRelativeTo(null);
		this.setDefaultCloseOperation(3);
		this.setSize(370, 243);
		this.setLayout(null);
		this.setResizable(false);
		this.setLocationRelativeTo(null);
		this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
		this.addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent e){
				//提示音效
				try {
					new Mention().play();
				} catch (IOException ex) {
					// TODO 自动生成的 catch 块
					ex.printStackTrace();
				}
				
				int option = JOptionPane.showConfirmDialog(
						ChangeModel.this, "是否退出游戏？", "退出提示", JOptionPane.YES_NO_OPTION);
				if(option == JOptionPane.YES_OPTION) {
					System.exit(0);
				} else {
					return;
				}
			}
		});	
		
		goBang.setBounds(0, 0, 370, 243);
		goBang.setLayout(null);
		this.add(goBang);
		
		init();
	}
	
	private void init() {
		top.setFont(new Font("华文行楷", 1, 30));
		top.setForeground(Color.MAGENTA);
		top.setBounds(63, 10, 250, 50);
		goBang.add(top);
		
		mm = new CircleButton("开始游戏");
		mm.setFont(new Font("华文行楷", 0, 20));
		mm.setForeground(Color.YELLOW);
		mm.setBounds(115, 75, 120, 30);
		mm.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				GoBang_PP mm = new GoBang_PP();
				mm.setVisible(true);
				ChangeModel.this.dispose();
			}
		});
		goBang.add(mm);
		
		mc = new CircleButton("游戏帮助");
		mc.setFont(new Font("华文行楷", 0, 20));
		mc.setForeground(Color.YELLOW);

		mc.setBounds(115, 135, 120, 30);
		mc.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Help help = new Help();
				help.setVisible(true);
				ChangeModel.this.dispose();
			}
		});
		goBang.add(mc);
		
		this.setVisible(true);
	}
	
	public static void main(String[] args) {
		ChangeModel main = new ChangeModel();
		main.setVisible(true);
	}
}
